/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package dequestackqueue;
import java.io.*;
/**
 *
 * @author User
 */
public class Main {
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {
        char c;
        String s;
        int w;
        Queue deque = new Queue();
        while(true)
	{
		BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
                c=(char)in.read();
                s=in.readLine();
		if(c=='>') {w=Integer.parseInt(s); deque.pushbegin(w);} else
		if(c=='<') deque.popbegin(); else
                if(c=='}') {w=Integer.parseInt(s); deque.pushend(w);} else
                if(c=='{') deque.popend();
		if(c=='#') break;

	}
        // TODO code application logic here
    }

}
